// pages/class/class.js
Page({
  data: {
    currentTab: 0,
    tabs: [
      { name: '作业', badge: '3' },
      { name: '打卡', badge: '12' },
      { name: '成员', badge: '' }
    ],
    homeworks: [
      {
        id: 1,
        title: '阅读《牛津树1级》第1-5本',
        deadline: '2024-01-15 18:00',
        completed: 25,
        total: 32,
        status: 'urgent'
      },
      {
        id: 2,
        title: '完成《轻松英语名著》第3章',
        deadline: '2024-01-16 18:00',
        completed: 18,
        total: 32,
        status: ''
      },
      {
        id: 3,
        title: '背诵单词20个',
        deadline: '2024-01-17 18:00',
        completed: 30,
        total: 32,
        status: ''
      }
    ],
    punches: [
      {
        id: 1,
        name: '小明',
        avatar: '👦',
        time: '2小时前',
        title: '今天读了3本书',
        books: [
          { title: '牛津树1-1' },
          { title: '牛津树1-2' },
          { title: '牛津树1-3' }
        ]
      },
      {
        id: 2,
        name: '小红',
        avatar: '👧',
        time: '3小时前',
        title: '完成了今日阅读任务',
        books: [
          { title: '轻松英语1' },
          { title: '轻松英语2' }
        ]
      },
      {
        id: 3,
        name: '小李',
        avatar: '👦',
        time: '4小时前',
        title: '阅读了5本绘本',
        books: [
          { title: 'Henry1' },
          { title: 'Henry2' },
          { title: 'Henry3' }
        ]
      }
    ],
    members: [
      {
        id: 1,
        name: '张老师',
        avatar: '👨‍🏫',
        role: '班主任',
        tag: 'teacher',
        tagText: '老师'
      },
      {
        id: 2,
        name: '小明',
        avatar: '👦',
        role: '学生',
        tag: 'me',
        tagText: '我'
      },
      {
        id: 3,
        name: '小红',
        avatar: '👧',
        role: '学生',
        tag: 'unpunch',
        tagText: '未打卡'
      },
      {
        id: 4,
        name: '小李',
        avatar: '👦',
        role: '学生',
        tag: '',
        tagText: ''
      }
    ]
  },

  onLoad() {
    // 页面加载时的逻辑
  },

  // 切换选项卡
  onTabTap(e) {
    const index = e.currentTarget.dataset.index
    this.setData({
      currentTab: index
    })
  },

  // 切换班级
  switchClass() {
    wx.showActionSheet({
      itemList: ['三年级一班', '三年级二班', '三年级三班'],
      success: (res) => {
        const classes = ['三年级一班', '三年级二班', '三年级三班']
        wx.showToast({
          title: `已切换到${classes[res.tapIndex]}`,
          icon: 'success'
        })
      }
    })
  },

  // 管理班级
  manageClass() {
    wx.showToast({
      title: '班级管理功能开发中',
      icon: 'none'
    })
  },

  // 复制班级码
  copyCode() {
    wx.setClipboardData({
      data: 'ABC123',
      success: () => {
        wx.showToast({
          title: '班级码已复制',
          icon: 'success'
        })
      }
    })
  },

  // 邀请学生
  inviteStudent() {
    wx.showModal({
      title: '邀请学生',
      content: '班级码：ABC123\n学生可通过班级码加入班级',
      showCancel: false
    })
  },

  // 搜索功能
  onSearch() {
    wx.showToast({
      title: '搜索功能开发中',
      icon: 'none'
    })
  },

  // 切换侧边栏
  toggleSidebar() {
    wx.showToast({
      title: '侧边栏功能开发中',
      icon: 'none'
    })
  },

  // 布置作业
  createHomework() {
    wx.showModal({
      title: '布置作业',
      content: '确定要布置新作业吗？',
      success: (res) => {
        if (res.confirm) {
          wx.showToast({
            title: '作业已布置',
            icon: 'success'
          })
        }
      }
    })
  },

  // 作业点击
  onHomeworkTap(e) {
    const homework = e.currentTarget.dataset.homework
    wx.showModal({
      title: homework.title,
      content: `截止时间：${homework.deadline}\n完成情况：${homework.completed}/${homework.total}`,
      showCancel: false
    })
  },

  // 发布打卡
  createPunch() {
    wx.showToast({
      title: '打卡功能开发中',
      icon: 'none'
    })
  },

  // 打卡点击
  onPunchTap(e) {
    const punch = e.currentTarget.dataset.punch
    wx.showModal({
      title: `${punch.name}的打卡`,
      content: punch.title,
      showCancel: false
    })
  },

  // 添加成员
  addMember() {
    wx.showToast({
      title: '添加成员功能开发中',
      icon: 'none'
    })
  },

  // 成员点击
  onMemberTap(e) {
    const member = e.currentTarget.dataset.member
    wx.showModal({
      title: member.name,
      content: `角色：${member.role}`,
      showCancel: false
    })
  },

  // 页面分享
  onShareAppMessage() {
    return {
      title: '班级管理 - 儿童英语分级阅读',
      path: '/pages/class/class'
    }
  }
}) 